package com;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.google.common.testing.FakeTicker;
import org.junit.Test;

import java.util.concurrent.TimeUnit;

/**
 * @author : zGame
 * @version V1.0
 * @Project: caffeinePro
 * @Package com
 * @Description: TODO
 * @date Date : 2022年01月07日 13:13
 */
public class CacheManager {
    
    @Test
    public void t1() {
        
        FakeTicker ticker = new FakeTicker(); // Guava's testlib
        Cache<String, String> cache = Caffeine.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES)
                .executor(Runnable::run).ticker(ticker::read).maximumSize(10).build();
        
        cache.put("key", "graph");
        ticker.advance(30,TimeUnit.MINUTES);
        assert (cache.getIfPresent("key")!=null);
        System.out.println(cache.getIfPresent("key"));
    }
    
}
